home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / ENCRYPT.SWG / 0019_Encryption Routine.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-24  |  1KB  |  47 lines

  1. {
  2.  JM> FUNCTION ConvertTxt (S : String) : String;
  3.  JM> Var X : Byte;
  4.  JM> Begin
  5.  JM>   ConvertTxt[0] := S[0];
  6.  JM>   For X := 1 to Length(S) do
  7.  JM>     ConvertTxt[X] := Chr(Ord(S[X]) XOR (Random(128) or 128));
  8.  JM> End;
  9.  JM> To encrypt a string, you just call ConvertTxt(string). Call
  10.  JM> the function again, with the same parameters to decrypt.
  11.  JM> Anyone have anything better, or have any suggestions?
  12.  
  13.   Here is basically the same function again.  However note the
  14.   RandSeed assignment - RandSeed is set to the length of the
  15.   string before a string is processed.  Since the length of
  16.   the string never changes, you can randomly pick any string
  17.   and be able to decrypt it.  RandSeed is used to make Random
  18.   return a specific sequence of psuedo-random numbers, and
  19.   this encryption method relies on the same sequence in order
  20.   for it to decrypt.
  21.  }
  22.  
  23.   PROCEDURE EnDecrypt(VAR S: String);
  24.   VAR
  25.     X: Byte;
  26.   BEGIN
  27.     RandSeed := Length(S);
  28.     FOR X := 1 TO Length(S) DO
  29.       S[X] := Chr(Ord(S[X]) XOR (Random(128) OR 128));
  30.   END;
  31.  
  32.   VAR
  33.     S: String;
  34.   BEGIN
  35.     Write('Enter a string: ');
  36.     Readln(S);
  37.     EnDecrypt(S);
  38.     WriteLn;
  39.     WriteLn;
  40.     Writeln('The encrypted string is ', S);
  41.     EnDecrypt(S);
  42.     WriteLn;
  43.     WriteLn;
  44.     Writeln('The decrypted string is ', S);
  45.   END.
  46.  
  47.